package ui

import dominio.JardinTablero
import dominio.Jugador
import org.uqbar.arena.bindings.NotNullObservable
import org.uqbar.arena.layout.ColumnLayout
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.Label
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.widgets.TextBox
import org.uqbar.arena.windows.Dialog
import org.uqbar.arena.windows.WindowOwner
import org.uqbar.commons.utils.Observable

@Observable
class PlayGame extends Dialog<Jugador> {
	new(WindowOwner owner, Jugador jt) {
		super(owner, jt)
		title = "Plants Vs Zombies Game"
		taskDescription = "Ingrese Nombre y presione Jugar!!!"
	}

	override protected addActions(Panel actionsPanel) {
		val botonJugar = new Button(actionsPanel).setAsDefault.setCaption("Jugar")
		botonJugar.onClick[|this.crearTablero]

		val botonSalir = new Button(actionsPanel).setAsDefault.setCaption("Salir")
		botonSalir.onClick[|this.close]

		new Label(actionsPanel).setText("Nombre")
		val textBoxFecha = new TextBox(actionsPanel)
		textBoxFecha.bindValueToProperty("nombre")

		var elementSelected = new NotNullObservable("nombre")
		botonJugar.bindEnabled(elementSelected)

	}

	override protected createFormPanel(Panel mainPanel) {
		val editorPanel = new Panel(mainPanel)
		editorPanel.setLayout(new ColumnLayout(100))
	}

	def void crearTablero() {
		this.cancel
		this.openDialog(new JardinTableroWindow(this, new JardinTablero(modelObject)))
	}

	def openDialog(Dialog<?> dialog) {
		dialog.onAccept[|]
		dialog.open

	}

}
